home *** CD-ROM | disk | FTP | other *** search
- // inpfield.h - generic input field class
- //
- // This header declares a set of classes for creating generic input
- // fields in dialog boxes. The InpField class is derived from TGroup,
- // and contains a TInputLine member (inpLine). The InpField
- // constructor is passed a pointer to an abstract InpData class.
- // The InpData class is used to store values that are input via the
- // TInputLine. InpData provides methods for validation, assignment,
- // string conversion, and error message text generation. Derive
- // your own InpData class with these methods overriden, and pass a pointer
- // to an instance of your class to InpField. A usable InpData subclass
- // is provided in this module for integer input (IntInpData). Here's
- // how you would use it within a dialog box's constructor:
- //
- // const initVal=1, minVal=1, maxVal=100;
- // IntInpData *myInt = new IntInpData(initVal, minVal, maxVal);
- //
- // const orgX=1, orgY=4, dataLen=2;
- // const char *myLabel="Input data here:";
- // InpField *myIntField = new InpField(
- // orgX, orgY, myInt, dataLen, myLabel
- // );
- // insert(myIntField);
- //
- // This would place a label "Input data here:" at (1,4) in the dialog box,
- // with an adjacent TInputLine that accomodates a data width of 2.
- // The TInputLine would initialy display "1" (initVal).
- // Any value entered into this field (via TAB or CR) is validated before it
- // is assigned to the IntInpData (myInt). If entered values are
- // outside 1-100, a message box appears to warn the user, and the
- // input field remains focused.
- //
- // If the focus is lost before TAB or CR are pressed (eg. mouse click),
- // then the InputLine is restored to the internally stored value (myInt).
- // This means that TAB or CR must be used to actually change the value.
- //
- //
- // Christensen OnLine, 1993
- //
- //$Log: inpfield.h $
- //Revision 1.4 1993/01/23 15:40:43 matt
- //Fixed/re-sent to CIS
- //
- //Revision 1.3 1993/01/23 14:38:18 matt
- //Uploaded to CIS
- //
- //Revision 1.2 1993/01/23 10:07:47 matt
- //Experiments with selectAll
- //
- //Revision 1.1 1993/01/13 20:57:22 matt
- //Input field with validation
- //
- #define Uses_TEvent
- #define Uses_TPoint
- #define Uses_TRect
- #define Uses_TInputLine
- #define Uses_TLabel
- #define Uses_MsgBox
- #define Uses_TGroup
- #include <tv.h>
-
- // Input field palette - transparent to TDialog for TInputLine and TLabel
- //
- #define cpInpField "\x01\x02\x03\x04\x05\x06\x07\x08"\
- "\x09\x0A\x0B\x0C\x0D\x0E\x0F\x10"\
- "\x11\x12\x13\x14\x15"
-
- const short InpDataMAXLEN = 80;
-
- ///////////////////////////////////////////////////////////////////////
- class InpData : public TObject
- ///////////////////////////////////////////////////////////////////////
- {
- public:
- virtual int isValid(char *)=0; // Is passed string valid?
- virtual InpData& operator = (char *)=0; // Assign internal value
- virtual char * getText(short len)=0; // Convert internal value
- virtual const char * errMsg()=0; // Err msg str for invalid val
-
- protected:
- static char convBuf[InpDataMAXLEN+1];
- };
-
- ///////////////////////////////////////////////////////////////////////
- class IntInpData : public InpData
- ///////////////////////////////////////////////////////////////////////
- {
- public:
- IntInpData(int initValue, int aMin, int aMax);
- virtual int isValid(char *);
- virtual InpData& operator = (char *);
- virtual char * getText(short len);
- virtual const char * errMsg();
-
- int value,min,max;
- };
-
- ///////////////////////////////////////////////////////////////////////
- class InpField : public TGroup
- ///////////////////////////////////////////////////////////////////////
- {
- public:
- InpField(int orgX, int orgY, InpData *theInpData,
- short aDataLen, const char *aLabel="");
- void handleEvent(TEvent& event);
- TPalette& getPalette() const;
- int getSizeX() {return size.x;}
-
- protected:
- InpData *inpData;
- short dataLen;
- Boolean dataSynced;
- TInputLine *inpLine;
- };
-